package com.google.gwt.livinglife.client.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.livinglife.client.LivingLife;
import com.google.gwt.livinglife.client.data.ResponseData;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ResponseBox extends Composite implements ClickHandler {
	private ResponseData response_data;
	private VerticalPanel main_panel = new VerticalPanel();
	private Label text = new Label();
	private VerticalPanel picture_container = new VerticalPanel();
	Image picture = new Image();
	Anchor author_link = new Anchor();
	FlowPanel body = new FlowPanel();
	
	public ResponseBox() {
		main_panel.add(body);
		main_panel.add(picture_container);
		body.add(author_link);
		body.add(text);
		initWidget(main_panel);
	}
	public void onClick(ClickEvent event) {
		
	}
	public void setResponse_data(ResponseData response_data) {
		this.response_data = response_data;
		author_link.setText(response_data.getAuthor().getNickname());
		author_link.setHref(LivingLife.getUserIdUrl(response_data.getAuthor().getId()));
		text.setText(response_data.getPost_text());
		if (response_data.getEmbeded_image() != null && !response_data.getEmbeded_image().isEmpty()) {
			picture.setUrl(response_data.getEmbeded_image());
			picture_container.add(picture);
		} else {
			picture_container.clear();
		}
	}
	public ResponseData getResponse_data() {
		return response_data;
	}

}
